<?php
/**
 * 借款预还管理
 */
namespace Admin\Controller\MaterialCheck;
use Think\Controller;

class MaterialcheckController extends Controller 
{
	/**
	 *	管理后台菜单初始化与用户登录身份验证
	 */
//	public function _initialize()
//	{
//		session('facId','51');
//		// 判断用户是否登陆
//		if (!session('?facId'))
//		{
//			$url = 'http://' . $_SERVER['HTTP_HOST'] .'/tp_bypal/index.php';
//			redirect($url);
//			exit;
//		}
//	}


	/**
	 *	材料审核列表页
	 */
	public function materialcheck_list() 
	{
		$select_custName = I("get.select_custName");
		$select_refertype = I("get.select_refertype");
		$select_custStatus = I("get.select_custStatus");
		$select_custID = I("get.cust_id");

		$search_array['select_custName'] = $select_custName;
		$search_array['select_refertype'] = $select_refertype;
		$search_array['select_custStatus'] = $select_custStatus;

		$this->assign("search_array",$search_array);

		$model_cust_reference = M('bypal_cust_reference');
		if ($select_custName != '') 
		{
			$model_custInfo = M('bypal_cust_info');
			$condition_custInfo['cust_name'] = array('like','%'.$select_custName.'%');
			$array_custInfo = $model_custInfo->where($condition_custInfo)->select();
			$array_custInfo_exist = array('0');
			foreach ($array_custInfo as $key => $value) 
			{
				array_push($array_custInfo_exist, $value['cust_id']);
			}
			$condition['ref_custid'] = array('in', $array_custInfo_exist);
		}
		if ($select_refertype != '') 
		{
			$condition['ref_type'] = $select_refertype;
		}
		if ($select_custStatus != '') 
		{
			$condition['ref_status'] = $select_custStatus;
		}
		if ($select_custID != '') 
		{
			$condition['ref_custid'] = $select_custID;
		}
		$array_data = $model_cust_reference->where($condition)->order('ref_status,ref_createdate desc')->select();
		foreach ($array_data as $key => $value) 
		{
			$model_cust_info = M('bypal_cust_info');
			$data_cust_info = $model_cust_info->where('cust_id='.$value['ref_custid'])->find();
			$array_data[$key]['cust_name'] = $data_cust_info['cust_name'];

			$model_cust_refertype = M('bypal_cust_refertype');
			$data_cust_refertype = $model_cust_refertype->where('refertype_id='.$value['ref_type'])->find();
			$array_data[$key]['refertype_name'] = $data_cust_refertype['refertype_name'];

			$model_cust_status = M('bypal_cust_status');
			$data_cust_status = $model_cust_status->where('status_id='.$value['ref_status'])->find();
			$array_data[$key]['status_name'] = $data_cust_status['status_name'];

			$array_data[$key]['ref_createdate'] = date('Y-m-d H:i:s', $value['ref_createdate']);
			if ($value['ref_conftime'] == '0') 
			{
				$array_data[$key]['ref_conftime'] = '------';
			}
			else
			{
				$array_data[$key]['ref_conftime'] = date('Y-m-d H:i:s', $value['ref_conftime']);
			}
		}

		$json_list = json_encode($array_data);
		$this->assign('json_list',$json_list);

		$model_cust_refertype = M('bypal_cust_refertype');
		$array_cust_refertype = $model_cust_refertype->select();
		$this->assign('array_cust_refertype',$array_cust_refertype);

		$model_cust_status = M('bypal_cust_status');
		$array_cust_status = $model_cust_status->select();
		$this->assign('array_cust_status',$array_cust_status);

		$this->display();
	}


	/**
	 *	材料审核详情
	 */
	public function materialcheck_detail() 
	{
		$this->display();
	}

}